import { request } from "@/utils/request";
import type {
  DeleteParams,
  QueryParams,
  QueryResult,
  QueryTeacherParams,
  QueryTeacherResult,
  QueryUserByIdResult,
  UserParams,
} from "./typing";
import type { PageResult, ResponseBody } from "@/api/typing";

/**新增用户 */
export const add = (params: UserParams) => {
  return request.post<UserParams, ResponseBody>("/user/add", params);
};

/**修改用户 */
export const update = (params: UserParams) => {
  return request.put<UserParams, ResponseBody>("/user/update", params);
};

/**分页查询用户 */
export const queryByPage = (params: QueryParams) => {
  return request.get<QueryParams, ResponseBody<PageResult<QueryResult>>>(
    "/user/page",
    { params }
  );
};

/**删除用户 */
export const del = (params: DeleteParams) => {
  return request.delete<DeleteParams, ResponseBody>("/user/delete", { params });
};

/**分页查询拥有教师角色的用户 */
export const queryTeacherUser = (params: QueryTeacherParams) => {
  return request.get<
    QueryTeacherParams,
    ResponseBody<PageResult<QueryTeacherResult>>
  >("/user/teacher", { params });
};

/**查询单个用户人员 */
export const queryById = (userId: string) => {
  return request.get<string, ResponseBody<QueryUserByIdResult[]>>("/user/id", {
    params: { userId },
  });
};
